package com.atguigu.gulimall.product.web;

import com.atguigu.gulimall.product.entity.CategoryEntity;
import com.atguigu.gulimall.product.service.CategoryService;
import com.atguigu.gulimall.product.vo.Catalog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @ ClassName IndexController
 * @ Description TODO
 * @ Author admin
 * @ Date 2021/2/22 9:35
 * @ Version 1.0
 */
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/", "index.html"})
    public String getIndex(Model model) {
        //获取所有的一级分类
        List<CategoryEntity> catagories = categoryService.getLevel1Catagories();
        System.out.println(catagories);
        model.addAttribute("catagories", catagories);
        return "index";
    }

    @GetMapping("index/catalog.json")
    @ResponseBody
    public Map<String,List<Catalog2Vo>> getCataLogJson(){

        Map<String,List<Catalog2Vo>> catalogJsonMap = categoryService.getCataLogJson();

        return catalogJsonMap;
    }


}
